home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Src / submit / gen_io2dr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  2.8 KB  |  144 lines

  1. /* gen_io2dr.c: write a DR submitted by an X400 incomming channel */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Src/submit/RCS/gen_io2dr.c,v 6.0 1991/12/18 20:28:02 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Src/submit/RCS/gen_io2dr.c,v 6.0 1991/12/18 20:28:02 jpo Rel $
  9.  *
  10.  * $Log: gen_io2dr.c,v $
  11.  * Revision 6.0  1991/12/18  20:28:02  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18. #include        <sys/types.h>
  19. #include        <sys/stat.h>
  20. #include        "head.h"
  21. #include     "q.h"
  22. #include        "dr.h"
  23.  
  24.  
  25. extern char             msg_fullpath[];
  26. extern long             msg_size;
  27. extern char        *dr_file;
  28. extern int              errno,
  29.             protocol_mode;
  30.  
  31. extern void    check_dr_crits ();
  32.  
  33. /* -- local routines -- */
  34. int            gen_io2dr();
  35. static void        reset_protocol_mode();
  36. static void        unset_protocol_mode();
  37.  
  38.  
  39.  
  40.  
  41. /* ---------------------  Begin  Routines  -------------------------------- */
  42.  
  43.  
  44.  
  45.  
  46. int gen_io2dr(qp)
  47. Q_struct *qp;
  48. {
  49.     struct stat             st_rec;
  50.     FILE                    *fp;
  51.     DRmpdu                  DeliveryReport, *dr;
  52.     char                    *fname,
  53.                 buf[MAXPATHLENGTH];
  54.     int                     retval;
  55.  
  56.     PP_TRACE (("gen_io2dr (protocol_mode=%d)", protocol_mode));
  57.  
  58.     dr_init (dr = &DeliveryReport);
  59.  
  60.     /* -- read the DR from stdin -- */
  61.  
  62.     if (rp_isbad (retval = rd_dr (dr, stdin))) {
  63.         switch (retval) {
  64.         case RP_EOF:
  65.             PP_LOG (LLOG_EXCEPTIONS,("no more input"));
  66.             return (RP_EOF);
  67.         case RP_PARM:
  68.             PP_LOG (LLOG_EXCEPTIONS, ("gen_io2dr Invalid param"));
  69.             return (RP_PARM);
  70.         default:
  71.             PP_LOG (LLOG_EXCEPTIONS, 
  72.                 ("gen_io2dr read error %d", retval));
  73.             return (retval);
  74.         }
  75.     }
  76.  
  77.     check_dr_crits (qp, dr);
  78.     trace_add (&dr -> dr_trace, trace_new());
  79.  
  80.     /* -- write the DR into the PP queue -- */
  81.  
  82.     (void) sprintf (buf, "%s/%s%d", msg_fullpath, dr_file,
  83.             DR_FILENO_DEFAULT);
  84.     fname = strdup (buf);
  85.     if ((fp = fopen (fname, "w")) == NULLFILE) {
  86.         PP_LOG (LLOG_FATAL, ("gen_io2dr (unable to open %s)", fname));
  87.         return (RP_FIO);
  88.     }
  89.  
  90.     unset_protocol_mode();
  91.     retval = wr_dr (dr, fp);
  92.     reset_protocol_mode();
  93.  
  94.     if (rp_isbad (retval)) {
  95.         PP_LOG(LLOG_EXCEPTIONS,
  96.                ("gen_io2dr Unable to write"));
  97.         (void) fclose (fp);
  98.         return (RP_PARM);
  99.     }
  100.  
  101.     if (check_close (fp) == NOTOK) {
  102.         PP_SLOG (LLOG_EXCEPTIONS, "gen_io2dr",
  103.              ("gen_io2dr Unable to close"));
  104.         return (RP_FIO);
  105.     }
  106.  
  107.     if (stat (fname, &st_rec) == NOTOK)
  108.         PP_LOG (LLOG_EXCEPTIONS,
  109.             ("gen_io2dr: Unable to stat %s %d", fname, errno));
  110.     msg_size = st_rec.st_size;
  111.  
  112.     dr_free (dr);
  113.  
  114.     PP_TRACE (("gen_io2dr returns (%d)", retval));
  115.  
  116.     return (retval);
  117. }
  118.  
  119.  
  120.  
  121. /* ---------------------  Static  Routines  ------------------------------- */
  122.  
  123.  
  124.  
  125. static void unset_protocol_mode ()
  126. {
  127.     reset_protocol_mode();
  128.     protocol_mode = 0;
  129.     return;
  130. }
  131.  
  132.  
  133. static void reset_protocol_mode ()
  134. {
  135.     static int      save = -1;
  136.  
  137.     if (save == -1)
  138.         save = protocol_mode;
  139.     else {
  140.         protocol_mode = save;
  141.         save = -1;
  142.     }
  143. }
  144.